package com.etoak.controller;


import com.etoak.common.core.vo.PageVo;
import com.etoak.common.core.vo.ResultVO;
import com.etoak.entity.Dishes;
import com.etoak.vo.DishesVo;
import com.etoak.service.DishesService;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author etoak
 * @since 2025-08-25
 */
@RestController
@RequestMapping("/dishes")
public class DishesController {

    @Autowired
    private DishesService dishesService;

    @PostMapping("/addDish")
    public ResultVO<Object> addDish(@Valid @RequestBody Dishes dishes) {
        dishesService.addDish(dishes);
        return ResultVO.success();
    }


    @GetMapping("/list")
    public ResultVO<Object> list(
            @RequestParam(required = false,defaultValue = "1") int pageNum,
            @RequestParam(required = false,defaultValue = "5") int pageSize,
            Dishes dishes
    ) {
        PageVo<DishesVo> list = dishesService.getList(pageNum, pageSize, dishes);
        return ResultVO.success(list);
    }

    @PutMapping("/{id}")
    public ResultVO<Object> updateDish(@PathVariable int id ,@RequestBody Dishes dishes) {
        dishesService.updateDish(id, dishes);
        return ResultVO.success();
    }

    @DeleteMapping("/{id}")
    public ResultVO<Object> deleteDish(@PathVariable int id) {
        dishesService.deleteDish(id);
        return ResultVO.success();
    }
}

